<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
    <c:set var="ctx" value="${pageContext.request.contextPath}" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>经销商变更记录</title>
    <jsp:include page="../../import.jsp" flush="true" />
</head>
<sys:funcAuth resCd="GSApply">
	<span id="GSApply" />
</sys:funcAuth>
<script type="text/javascript">
    var grid = null;
    var splId = '${splId}';
    $(function () {
        splId = '${splId}';
        var _url = '<%=path%>/product/splApplyInfo/initSplInfoApplyList.do?splId=' + splId ;
        $("#ligergrid1").ligerGrid({
            url: _url,
            method : 'get',
            columns: [
                { display: '供应商名称-变更前', name: 'splNmB', width: '15%' },
                { display: '供应商名称-变更后', name: 'splNm', width: '15%' },
                { display: '统一社会信用代码-变更前', name: 'succB', width: '15%' },
                { display: '统一社会信用代码-变更后', name: 'succ', width: '15%' },
                { display: '营业执照号-变更前', name: 'bizLicNoB', width: '15%' },
                { display: '营业执照号-变更后', name: 'bizLicNo', width: '15%' },
                { display: '税务登记号-变更前', name: 'taxRegNoB', width: '15%' },
                { display: '税务登记号-变更后', name: 'taxRegNo', width: '15%' },
                { display: '组织机构代码-变更前', name: 'orgCodeB', width: '15%' },
                { display: '组织机构代码-变更后', name: 'orgCode', width: '15%' },
                { display: '流程编号', width: '15%',
                    render: function (rowdata, rowindex, value){
                        var h= "";
                        if(StringUtils.isNotEmpty(rowdata.pno)){
                            h='<a href="javascript:showFlow(';
                            h+="'"+rowdata.pinstId+"'";
                            h+=",'"+rowdata.audStsCd+"'";
                            h+=",'"+rowdata.id+"'";
                            h+=')">'+rowdata.pno+'</a>';
                        }
                        return h;
                    }
                },
                { display: '流程变更备注-变更前', name: 'chngFlowRemB', width: '15%' },
                { display: '流程变更备注-变更后', name: 'chngFlowRem', width: '15%' },
                { display: '创建时间', name: 'crtTm', width: '15%' , render: renderDate },
                getOperateColumn()
            ],
            pageSize:10,
            root:'rows',
            record:'total',
            hideLoadButton : true,
            width: '100%',
            height:'100%',
            heightDiff:-2,
            rownumbers:true,
        });
        
        var isShowCmtBtn = $("#isShowCmtBtn");
        if(isShowCmtBtn.length){
        	$("#btnDiv").show();
		}
        
        grid = liger.get("ligergrid1");
        grid.setHeight(100);

    });
    //显示流程
    function showFlow(_pInstId,_audStsCd,_businessKey){
        if(StringUtils.isEmpty(_pInstId)){
            UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
            return;
        }
        var _formUrl = "/product/splApplyInfo/toModifyPage.do?audStsCd=1@@applyId=";
        var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
        Add_navTab('tab_spl_apply_flow_'+_pInstId,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }
    function addFlowStart(){
   	 $.ajax({
            type: 'post',
            dataType: 'json',
            data: {
           	 splId: splId,
            },
            url: '<%=path%>/product/splApplyInfo/addSplGSApplyFlowStart.do',
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                	$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    grid.reload();
                } else {
                    UIUtils.alertErrorHold1(msg.info);
                }
            }
        });
   }
    function getOperateColumn(){
        return {
            display: '操作',width:'25%',
            render: function (rowdata, rowindex, value){
                var h="";
                /* if(rowdata.audStsCd=="0"){
                    h+='<a class="sq-button-hasicon" href="javascript:startFlow(';
                    h+="'"+rowdata.id+"'";
                    h+=')"><i class="sqBtnIco_6"></i>发起审核流程</a>';
                } */
                h+='<a class="sq-button-hasicon" href="javascript:showDetail(';
                h+="'"+rowdata.id+"'";
                h+=')"><i class="sqBtnIco_2"></i>查看变更详情</a>';
                return h;
            }
        };
    }

    //供应商变更详情
    function showDetail(_id){
        if (!_id) {
            return;
        }
        $.ligerDialog.SQopen({
            cls: 'noBorder_Dialog',
            width: 1100,
            height: 500,
            title: '变更记录信息',
            url: '<%=path%>/product/splApplyInfo/toSplInfoApplyChangeDetail.do?id='+_id,
            buttons: [
                {
                    text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
                    onclick: function (item, Dialog) {
                        //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                        if (Dialog.onCancel) Dialog.onCancel();
                    }
                }
            ]
        });
        //Add_navTab('tab_spl_bsc_info_apply_'+_id,'供应商变更详情',"<%=path%>/product/splApplyInfo/toSplInfoApplyChangeDetail.do?id="+_id);
    }


    //发起审核流程
    function startFlow(_id){
        if(!_id)return;
        //发起流程确认
        $.ligerDialog.confirm(FlowConstant.FLOW_ADD_START_CONFIRM, function (flag) {
            if(flag == false)return;
            var modelTyp = FlowConstant.FLOW_MODEL_TYP_SPL_CHG;//流程业务分类-供应商信息变更
            if(StringUtils.isEmpty(modelTyp)){
                console.log("modelTyp is null");
                return;
            }
            var flowDialog = $.ligerDialog.SQopen({
                url: '<%=path%>/flow/flow/toForStartListPage.do?modelTyp='+modelTyp,
                width: 700,
                height:400,
                title : '请选择要发起的流程',
                buttons: [{
                    text: "确定", type: 'ok', cls: 'l-dialog-btn-ok',
                    onclick: function (item, Dialog) {
                        if (Dialog.onOk) Dialog.onOk();
                    }
                }, {
                    text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
                    onclick: function (item, Dialog) {
                        if (Dialog.onCancel) Dialog.onCancel();
                    }
                }
                ],
                onClose: function () {
                    var json = flowDialog._DATA;
                    console.log(json);
                    if(!json){
                        return;
                    }
                    var wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting",onClose: function () {}});
                    $.ajax({
                        type: 'post',
                        dataType:'json',
                        data:{
                            id:_id,
                            procDefKey:json.procDefKey,
                            procDefId:json.procDefId,
                            procNo:json.procNo
                        },
                        url: '<%=path%>/product/splApplyInfo/addSplChangeFlowStart.do',
                        success:function(msg){
                            wait_dialog.close();
                            if(msg.success == 1){
//	          					 UIUtils.alertSuccessHold1(msg.info);
                                /* if(lxxz=="true"){
                                   Remove_navTab();
                                   return;
                                } */
                                var url = '<%=path%>/flow/flow/getFlowNextAssigne.do?key=' + msg.info;
                                FlowUtils.alertNextFlowAssign(url);
                                grid.reload();
                            }else{
                                UIUtils.alertErrorHold1(msg.info);
                            }
                        }
                    });
                }
            });
        });
    }

    function iframeResize () {
        if (parent.mainApp) {
            parent.mainApp.parentTab.onResize();
        };
    }

    //格式化时间
    function renderDate(rowdata, index, value){
        var dateStr = "";
        if(null != value){
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }

</script>

<body class="iframeBody">
<div class="Wrapper">
<div class="btnsBox" id="btnDiv">
	<sys:funcAuth resCd="GSApply">
        <!-- 2020-06-09 19:15:35 三方数据关停-->
		<%--<span id="prj_lnk_comp_add_btn_id"
			  class="sq-button sq-button-round" id="GSApply" onclick="addFlowStart();">执行工商变更
		</span>--%>
	</sys:funcAuth>
</div>
</div>
<div id="ligergrid1" class="sq-grid"></div>
</body>
</html>